package com.k.demo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.k.demo.entity.ConstantTermKind;
import com.k.demo.entity.Food;
import com.k.demo.mapper.ConstantTermKindMapper;
import com.k.demo.service.ConstantTermKindService;

@Service
public class ConstantTermKindServiceImpl implements ConstantTermKindService {
	
	@Autowired
	private ConstantTermKindMapper constantTermKindMapper;

	//获取全部的常数项类别
	public List<ConstantTermKind> getAll() {

		return constantTermKindMapper.getAll();
		
	}

	//通过id查找
	public ConstantTermKind getById(int id) {
		// TODO Auto-generated method stub
		return constantTermKindMapper.getById(id);
	}

	//假单个删除
	public int falseDeleteById(int id) {
		
		int count = constantTermKindMapper.falseDeleteById(id) ;
		
		if(count>0) {
			
			return count;
					
		}
				
		return 0;
	}

	//真单个删除
	public int trueDeleteById(int id) {
		
		int count = constantTermKindMapper.trueDeleteById(id);
		
		if(count>0) {
			
			return count;
					
		}
				
		return 0;
	}

	//批量删除
	public boolean deleteByGroup(List<Integer> list) {
		
		return constantTermKindMapper.deleteByGroup(list);
		
	}

	//修改常数项类别
	public ConstantTermKind modifyConstantTermKind(ConstantTermKind constantTermKind) {
		
		int count = constantTermKindMapper.modifyCTK(constantTermKind);
		
		if(count > 0) {
			
			return constantTermKind;
			
		}
		return null;
	}

	//增加常数项类别
	public ConstantTermKind addConstantTermKind(ConstantTermKind constantTermKind) {
		
		int count = constantTermKindMapper.insertCTK(constantTermKind);
		
		if(count>0) {
			
			return constantTermKind;
		}
		
		return null;
	}

	//分页显示全部的常数项类别
	public PageInfo<ConstantTermKind> getPage(int pageNum, int pageSize) {
		
		PageHelper.startPage(pageNum,pageSize);
		
		return new PageInfo<ConstantTermKind>(constantTermKindMapper.getAll());

	}

	//分页显示通过name的查询结果
	public PageInfo<ConstantTermKind> getPageByName(int pageNum, int pageSize, String name) {
		
		PageHelper.startPage(pageNum,pageSize);
		
		return new PageInfo<ConstantTermKind>(constantTermKindMapper.selectByName(name));
	}

}
